package vn.fpt.fsoft.action.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.springframework.web.struts.ActionSupport;

import vn.fpt.fsoft.action.user.AddUserAction;
import vn.fpt.fsoft.bl.ManageUsersBL;
import vn.fpt.fsoft.bl.UserBo;
import vn.fpt.fsoft.entity.AdminAccountInfo;
import vn.fpt.fsoft.entity.User;
import vn.fpt.fsoft.form.admin.AddAdminForm;
import vn.fpt.fsoft.user.form.UserForm;

public class AddAdminAction extends ActionSupport{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
		ManageUsersBL manageUserBL = (ManageUsersBL) getWebApplicationContext().getBean("ManageUserBL");
			AddAdminForm f = (AddAdminForm)form;
			AdminAccountInfo admin = new AdminAccountInfo();
			
			//copy Userform to model
			BeanUtils.copyProperties(admin, f);
			
			//save it
			manageUserBL.addAdminUser(admin);
		        
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("false");
		}
	}
	
	
}
